package com.ymttest.database.sqlwapper.shenqisettlement;

import java.util.HashMap;
import java.util.List;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.shenqisettlement.DistributorSettlementDetail;

public class DistributorSettlementDetailWrapper {

	SqlManager manager;

	public DistributorSettlementDetailWrapper() {
		manager = new SqlManager("shenqisettlement");
	}

	@SuppressWarnings("unchecked")
	public DistributorSettlementDetail selectByPrimaryKey(long id) {

		DistributorSettlementDetail distributorSettlementDetail = new DistributorSettlementDetail();
		List<DistributorSettlementDetail> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.shenqisettlement.DistributorSettlementDetailMapper.selectByPrimaryKey",
						id);
		manager.commit();

		if (result.size() > 0) {
			distributorSettlementDetail = result.get(0);
		}

		return distributorSettlementDetail;
	}
	
	@SuppressWarnings("unchecked")
	public List<DistributorSettlementDetail> selectByOrderId(long orderId) {

		List<DistributorSettlementDetail> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.shenqisettlement.DistributorSettlementDetailMapper.selectByOrderId",
						orderId);
		manager.commit();

		return result;
	}
	
	@SuppressWarnings("unchecked")
	public DistributorSettlementDetail selectByPaymentIdAndOrderIdAndDistributorId(
			long paymentId, long orderId, long distributorId) {

		HashMap<String, Long> map = new HashMap<>();

		map.put("payment_id", paymentId);
		map.put("order_id", orderId);
		map.put("distributor_id", distributorId);

		DistributorSettlementDetail distributorSettlementDetail = new DistributorSettlementDetail();
		List<DistributorSettlementDetail> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.shenqisettlement.DistributorSettlementDetailMapper.selectByPaymentIdAndOrderIdAndDistributorId",
						map);
		manager.commit();

		if (result.size() > 0) {
			distributorSettlementDetail = result.get(0);
		}

		return distributorSettlementDetail;
	}
	
	@SuppressWarnings("unchecked")
	public DistributorSettlementDetail selectByPaymentIdAndOrderIdAndDistributorIdAndSettlementType(
			long paymentId, long orderId, long distributorId, Integer settlementType) {

		HashMap<String, Object> map = new HashMap<>();

		map.put("payment_id", paymentId);
		map.put("order_id", orderId);
		map.put("distributor_id", distributorId);
		map.put("settlement_type", settlementType);

		DistributorSettlementDetail distributorSettlementDetail = new DistributorSettlementDetail();
		List<DistributorSettlementDetail> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.shenqisettlement.DistributorSettlementDetailMapper.selectByPaymentIdAndOrderIdAndDistributorIdAndSettlementType",
						map);
		manager.commit();

		if (result.size() > 0) {
			distributorSettlementDetail = result.get(0);
		}

		return distributorSettlementDetail;
	}
	
	@SuppressWarnings("unchecked")
	public DistributorSettlementDetail selectRefundedByPaymentIdAndOrderIdAndDistributorId(
			long paymentId, long orderId, long distributorId, String bizId) {

		HashMap<String, Object> map = new HashMap<>();

		map.put("payment_id", paymentId);
		map.put("order_id", orderId);
		map.put("distributor_id", distributorId);
		map.put("biz_id", bizId);

		DistributorSettlementDetail distributorSettlementDetail = new DistributorSettlementDetail();
		List<DistributorSettlementDetail> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.shenqisettlement.DistributorSettlementDetailMapper.selectRefundedByPaymentIdAndOrderIdAndDistributorId",
						map);
		manager.commit();

		if (result.size() > 0)
			distributorSettlementDetail = result.get(0);
		else
			return null;

		return distributorSettlementDetail;
	}
	
	@SuppressWarnings("unchecked")
	public DistributorSettlementDetail selectByPaymentIdAndOrderIdAndDistributorIdAndSettlementType(
			long paymentId, long orderId, long distributorId, String bizId, Integer settlementType) {

		HashMap<String, Object> map = new HashMap<>();

		map.put("payment_id", paymentId);
		map.put("order_id", orderId);
		map.put("distributor_id", distributorId);
		map.put("biz_id", bizId);
		map.put("settlement_type", settlementType);

		DistributorSettlementDetail distributorSettlementDetail = new DistributorSettlementDetail();
		List<DistributorSettlementDetail> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.shenqisettlement.DistributorSettlementDetailMapper.selectByPaymentIdAndOrderIdAndDistributorIdAndSettlementType",
						map);
		manager.commit();

		if (result.size() > 0)
			distributorSettlementDetail = result.get(0);
		else
			return null;

		return distributorSettlementDetail;
	}
	
	@SuppressWarnings("unchecked")
	public List<DistributorSettlementDetail> selectRefundedByPaymentIdAndOrderId(
			long paymentId, long orderId, String bizId) {

		HashMap<String, Object> map = new HashMap<>();

		map.put("payment_id", paymentId);
		map.put("order_id", orderId);
		map.put("biz_id", bizId);

		List<DistributorSettlementDetail> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.shenqisettlement.DistributorSettlementDetailMapper.selectRefundedByPaymentIdAndOrderId",
						map);
		manager.commit();

		return result;
	}
	
	@SuppressWarnings("unchecked")
	public List<DistributorSettlementDetail> selectPartnerRefundedByPaymentIdAndOrderId(
			long paymentId, long orderId, String bizId) {

		HashMap<String, Object> map = new HashMap<>();

		map.put("payment_id", paymentId);
		map.put("order_id", orderId);
		map.put("biz_id", bizId);

		List<DistributorSettlementDetail> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.shenqisettlement.DistributorSettlementDetailMapper.selectPartnerRefundedByPaymentIdAndOrderId",
						map);
		manager.commit();

		return result;
	}
	
	@SuppressWarnings("unchecked")
	public DistributorSettlementDetail selectRefundedByPaymentIdAndOrderIdAndDistributorIdAndSettlementType(
			long paymentId, long orderId, long distributorId, String bizId, Integer settlementType) {

		HashMap<String, Object> map = new HashMap<>();

		map.put("payment_id", paymentId);
		map.put("order_id", orderId);
		map.put("distributor_id", distributorId);
		map.put("biz_id", bizId);
		map.put("settlement_type", settlementType);

		DistributorSettlementDetail distributorSettlementDetail = new DistributorSettlementDetail();
		List<DistributorSettlementDetail> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.shenqisettlement.DistributorSettlementDetailMapper.selectRefundedByPaymentIdAndOrderIdAndDistributorIdAndSettlementType",
						map);
		manager.commit();

		if (result.size() > 0)
			distributorSettlementDetail = result.get(0);
		else
			return null;

		return distributorSettlementDetail;
	}
	
	public static void main(String[] args) {
		
		DistributorSettlementDetailWrapper wrapper = new DistributorSettlementDetailWrapper();
		
		System.out.println(wrapper.selectByPrimaryKey(1));
	}
}
